package com.SmartCare.controller.manager;


import com.SmartCare.common.Result;
import com.SmartCare.service.apiLog.ApiLogService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 接口调用日志表 前端控制器
 */
@RestController
@RequestMapping("/api-log")
public class ApiLogController {

    @Resource
    ApiLogService apiLogService;

    //根据养老院名获取日志信息
    @GetMapping("/query")
    public Result query(@RequestParam String name) {
        return apiLogService.query(name);
    }

    //根据养老院名和查询信息获取分页日志信息
    @GetMapping("/search")
    public Result search(@RequestParam Integer pageNum,
                         @RequestParam Integer pageSize,
                         @RequestParam String keyword,
                         @RequestParam String type,
                         @RequestParam String name) {
        return apiLogService.search(pageNum, pageSize, keyword, type, name);
    }

    //导出记录
    @GetMapping("/export/{name}")
    public void export(HttpServletResponse response, @PathVariable String name) {
        apiLogService.export(response, name);
    }

    // 根据模块分类获取日志排行榜 访问报告
    @GetMapping("/query-top-logs")
    public Result queryTopLogs(@RequestParam String careHomeName,
                               @RequestParam String startTime,
                               @RequestParam String endTime) {
        return apiLogService.queryTopLogs(careHomeName, startTime, endTime);
    }

    // 根据用户分类获取日志排行榜
    @GetMapping("/top-by-user")
    public Result topByUser(@RequestParam String careHomeName,
                            @RequestParam String startTime,
                            @RequestParam String endTime) {
        return apiLogService.topByUser(careHomeName, startTime, endTime);
    }
}

